<?php
/**
 * excel导入导出Model
 * @author 王涛
 * @DataTime 2018-08-08T15:12:23+0800
 */
namespace app\api\model;
use think\Model;
class PhpexcelModel extends Model{
    protected $table = 'orange_device';
    protected function initialize()
    {
        parent::initialize();
        //TODO:自定义的初始化
    }
    /**
     * obd Excel导入 mysql
     * @author 王涛
     * @DataTime 2018-08-08T15:12:23+0800
     * @return   [type]                   [description]
     */
    public function obdExcelToMysql($data)
    {   
        $insertdata = array();
        foreach ($data as $key => $value) {
            if ( empty($this->where('id='.$value[6])->find()) ) {
                $data1['id'] = $value[6];
                $data1['create_time'] = date("Y-m-d H:i:s",time());
                $data1['batche'] = $value[2];
                $data1['sim_no'] = $value[4];
                $data1['device_name'] = $value[6];
                $data1['status'] = 2;
                $data1['utime'] = time();
                array_push($insertdata,$data1);
            }
        }        
        // var_dump($data);die;
        $obd = $this->insertAll($insertdata,false);
        return $obd;
    }
    /**
     * mysql数据导出到Excel
     * @author 王涛
     * @DataTime 2018-08-08T17:11:36+0800
     * @param    [type]                   $data [description]
     * @return   [type]                         [description]
     */
    public function mysqlToExcel($data)
    {

    }
}
